package com.hpu.callback;

import android.os.Handler;
import android.os.Message;

import com.hpu.constants.HttpConstants;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * 实现了个人信息业务类的回调接口
 * @author Administrator
 *
 */
public class XueyuanNewsCallback implements Callback{

private Handler handler;
	
	public XueyuanNewsCallback(Handler handler) {
		this.handler=handler;
	}
	
	@Override
	public void onFailure(Call arg0, IOException arg1) {
		handler.sendEmptyMessage(HttpConstants.QUERY_XUEYUAN_NEWS_ERROR);
	}

	@Override
	public void onResponse(Call arg0, Response arg1) throws IOException {
		String result = arg1.body().string();
		if (result != null && result.equals("404"))
			handler.sendEmptyMessage(HttpConstants.VPN_TOOLONG);
		else if (result.equals("501")) {
			handler.sendEmptyMessage(HttpConstants.KEY_ERROR);
		} else if (result.equals("502")) {
			handler.sendEmptyMessage(HttpConstants.NEED_INFO);
		} else{
			Message message = new Message();
			message.what = HttpConstants.QUERY_XUEYUAN_NEWS_SUCCESS;
			message.obj = result;
			handler.sendMessage(message);
		}
	}
}
